import { defineStore } from "pinia";
import { ref } from "vue";
import {selectRoles} from '../../src/utils/selectRole'
export const useProjectStore = defineStore(
  "project",
  () => {
    let autoReLoad = ref(false)
    let projectInfo = ref(null);
    let projectCount = ref(0);
    localStorage.getItem("project")
      ? (projectInfo.value = JSON.parse(
          localStorage.getItem("project")
        ).projectInfo)
      : (projectInfo.value = {});
 
    let setProjectInfo = async(value) => {
      
      projectInfo.value = value;
      setTimeout(async()=>{
        await selectRoles(value)
      })
     
      
    };
    return { projectInfo, setProjectInfo, projectCount,autoReLoad };
  },

  // 使用插件piniaPluginPersistedstate配置持久化存储
  {
    debug: true,
    storage: localStorage,
    persist: true,
    path: ["projectInfo"], //用于指定 state 中哪些数据需要被持久化
  }
);
